<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <div id="box">
    <ul>
      <li>王者农药</li>
      <li>英雄联盟</li>
      <li>qq飞车</li>
      <li>qq炫舞</li>
    </ul>
  </div>
  <script>
    var box = document.getElementById("box")
    // box.innerHTML = "<h1>侠盗飞车</h1>" 
    // 1.创建元素 document.createElement("标签名");
    var h1 = document.createElement("h1");
    h1.innerHTML = "侠盗飞车";
    h1.style.color = "red";
    //2.添加元素  父元素.appendChild(元素) 添加到父元素的最后位置
    box.appendChild(h1)
    //3. 添加元素到参照物前面  父元素.insertBefore(新元素,参照物)
    var ul = document.getElementsByTagName("ul")[0];
    var feiche = box.firstElementChild.children[2];
    // 创建的新元素
    var baoli = document.createElement("li");
    baoli.innerHTML = "暴力摩托";
    ul.insertBefore(baoli, feiche)


  </script>
</body>

</html>